import { request } from '@/api/request';
import { HttpMethod } from '@/services/types';

import DynamicStruct = API.DynamicStruct;
import DynamicComment = API.DynamicComment;

/**
 * POST /dynamic 添加动态
 * @param params
 * @param options
 */
export async function resAddDynamic(
  params: API.AddDynamicParams,
  options?: { [key: string]: any }
) {
  return request<R<null>>('/dynamic', {
    method: HttpMethod.POST,
    data: params,
    ...(options || {}),
  });
}

/**
 * GET /dynamic 动态列表
 * @param params
 * @param options
 */
export async function resDynamicList(
  params: API.DynamicListParams,
  options?: { [key: string]: any }
) {
  return request<API.PaginationResult<DynamicStruct>>('/dynamic', {
    method: HttpMethod.GET,
    params,
    ...(options || {}),
  });
}

/**
 * GET /dynamic/:id 指定用户动态列表
 * @param userId
 * @param params
 * @param options
 */
export async function resUserDynamicList(
  userId: number,
  params: API.DynamicListParams,
  options?: { [key: string]: any }
) {
  return request<API.PaginationResult<DynamicStruct>>('/dynamic/' + userId, {
    method: HttpMethod.GET,
    params,
    ...(options || {}),
  });
}

/**
 * PUT /dynamic/:id 修改动态
 * @param id
 * @param params
 * @param options
 */
export async function resChangeDynamic(
  id: number,
  params: API.AddDynamicParams,
  options?: { [key: string]: any }
) {
  return request<R<null>>('/dynamic/' + id, {
    method: HttpMethod.PUT,
    data: params,
    ...(options || {}),
  });
}

/**
 * Delete /dynamic/:id 删除动态
 * @param id
 * @param options
 */
export async function resDeleteDynamic(
  id: number,
  options?: { [key: string]: any }
) {
  return request<R<null>>('/dynamic/' + id, {
    method: HttpMethod.DELETE,
    ...(options || {}),
  });
}

/**
 * GET /dynamic/:id 动态详情
 * @param id
 * @param options
 */
export async function resDynamicDetail(
  id: number,
  options?: { [key: string]: any }
) {
  return request<API.DynamicStruct>('/dynamic/' + id, {
    method: HttpMethod.GET,
    ...(options || {}),
  });
}

/**
 * GET /dynamic/comment/:id 获取动态评论
 * @param id
 * @param params
 * @param options
 */
export async function resDynamicComment(
  id: number,
  params: API.PaginationQueryBase,
  options?: { [key: string]: any }
) {
  return request<API.PaginationResult<DynamicComment>>(
    '/dynamic/comment/' + id,
    {
      params,
      method: HttpMethod.GET,
      ...(options || {}),
    }
  );
}

/**
 * PATCH /dynamic/comment/:id 回复动态评论
 * @param id
 * @param params
 * @param options
 */
export async function resReplyDynamicComment(
  id: number,
  params: API.ReplyDynamicParams,
  options?: { [key: string]: any }
) {
  return request<R<null>>('/dynamic/comment/' + id, {
    method: HttpMethod.PATCH,
    data: params,
    ...(options || {}),
  });
}

/**
 * POST /dynamic/comment/:id 获取动态评论
 * @param id
 * @param params
 * @param options
 */
export async function resAddDynamicComment(
  id: number,
  params: API.AddDynamicCommentParams,
  options?: { [key: string]: any }
) {
  return request<R<API.DynamicComment>>('/dynamic/comment/' + id, {
    method: HttpMethod.POST,
    data: params,
    ...(options || {}),
  });
}
